/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Statistics.java
 *
 * Created on 18-08-2011, 21:31:31
 */
package tuitionmanagement.gui;

import Business.StaticticBuss;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import tuitionmanagement.DAO.StaticticsDao;
import tuitionmanagement.entity.StaticticEntity;

/**
 *
 * @author XUAN
 */
public class Statistics extends javax.swing.JPanel {

    boolean cbbox = false;
    Vector vRow = new Vector();
    StaticticEntity st = new StaticticEntity();
    StaticticBuss stbuss = new StaticticBuss();
    StaticticsDao stdao = new StaticticsDao();
    ArrayList<StaticticEntity> list;

    /** Creates new form Statistics */
    public Statistics() {
        initComponents();
        stdao.getcmbClassName(cmbClassName, "ClassName");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbStudentTakeExam = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        btnReport = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        txtMeassage = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        lbNumberStudent = new javax.swing.JLabel();
        jPanel10 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        btnStaticticsTakeExam = new javax.swing.JButton();
        btnStaticticNoExam = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cmbClassName = new javax.swing.JComboBox();
        dcFrom = new com.toedter.calendar.JDateChooser();
        dcTo = new com.toedter.calendar.JDateChooser();

        setLayout(new java.awt.GridBagLayout());

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("Statictics");
        jPanel1.add(jLabel1, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 5, 0);
        add(jPanel1, gridBagConstraints);

        jPanel3.setLayout(new java.awt.GridBagLayout());

        tbStudentTakeExam.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "StudentId", "StudentName", "TotaPaidlMoney", "PaidMoney", "Balance"
            }
        ));
        jScrollPane1.setViewportView(tbStudentTakeExam);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.ipadx = 650;
        gridBagConstraints.ipady = 150;
        jPanel3.add(jScrollPane1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 20, 10, 20);
        add(jPanel3, gridBagConstraints);

        jPanel4.setLayout(new java.awt.GridBagLayout());

        btnReport.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnReport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tuitionmanagement/icon/export1.png"))); // NOI18N
        btnReport.setText("Report");
        jPanel4.add(btnReport, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 10, 42);
        add(jPanel4, gridBagConstraints);

        jPanel5.setLayout(new java.awt.GridBagLayout());
        jPanel5.add(txtMeassage, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 9, 0);
        add(jPanel5, gridBagConstraints);

        jPanel6.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        add(jPanel6, gridBagConstraints);

        jPanel7.setLayout(new java.awt.GridBagLayout());

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("Numbers Of Student:");
        jPanel7.add(jLabel5, new java.awt.GridBagConstraints());

        lbNumberStudent.setFont(new java.awt.Font("Tahoma", 0, 12));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.ipadx = 50;
        jPanel7.add(lbNumberStudent, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 20);
        add(jPanel7, gridBagConstraints);

        jPanel10.setLayout(new java.awt.GridBagLayout());

        jPanel9.setLayout(new java.awt.GridBagLayout());

        btnStaticticsTakeExam.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnStaticticsTakeExam.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tuitionmanagement/icon/check2.png"))); // NOI18N
        btnStaticticsTakeExam.setText("Statictics Take Exam");
        btnStaticticsTakeExam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStaticticsTakeExamActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(6, 33, 9, 27);
        jPanel9.add(btnStaticticsTakeExam, gridBagConstraints);

        btnStaticticNoExam.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnStaticticNoExam.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tuitionmanagement/icon/delete2.png"))); // NOI18N
        btnStaticticNoExam.setText("Statictics No Exam   ");
        btnStaticticNoExam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStaticticNoExamActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(6, 33, 9, 27);
        jPanel9.add(btnStaticticNoExam, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        jPanel10.add(jPanel9, gridBagConstraints);

        jPanel2.setLayout(new java.awt.GridBagLayout());

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("ClassName:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 5);
        jPanel2.add(jLabel2, gridBagConstraints);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("From:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 5);
        jPanel2.add(jLabel3, gridBagConstraints);

        jLabel4.setText("To:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(5, 15, 0, 5);
        jPanel2.add(jLabel4, gridBagConstraints);

        cmbClassName.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbClassNameItemStateChanged(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.ipadx = 150;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(cmbClassName, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.ipadx = 140;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
        jPanel2.add(dcFrom, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.ipadx = 140;
        gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 1);
        jPanel2.add(dcTo, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 9, 0);
        jPanel10.add(jPanel2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 18, 0, 0);
        add(jPanel10, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void loadTableStExamStatictics() {
        vRow.clear();
        String classname = cmbClassName.getSelectedItem().toString();
        Date searchFrom = dcFrom.getDate();
        Date searchTo = dcTo.getDate();
        list = stbuss.getStaticticExamByClassNameDate(classname, searchFrom, searchTo);

        for (int i = 0; i < list.size(); i++) {
            Vector v = new Vector();

            st = list.get(i);
            v.addElement(st.getStudentId());
            v.addElement(st.getStudentName());
            v.addElement(st.getTotalMoney());
            v.addElement(st.getPaidMoney());
            v.addElement(st.getBanlance());

            vRow.addElement(v);
        }

        Vector vCol = new Vector();
        vCol.addElement("StudentId");
        vCol.addElement("StudentName");
        vCol.addElement("TotalMoney");
        vCol.addElement("PaidMoney");
        vCol.addElement("Balance");

        DefaultTableModel tblModel = new DefaultTableModel(vRow, vCol);
        tbStudentTakeExam.setModel(tblModel);
    }

    private void loadTableStNoExamStatictics() {
        vRow.clear();
        String classname = cmbClassName.getSelectedItem().toString();
        Date searchFrom = dcFrom.getDate();
        Date searchTo = dcTo.getDate();
        list = stbuss.getStaticticNoExamByClassNameDate(classname, searchFrom, searchTo);

        for (int i = 0; i < list.size(); i++) {
            Vector v = new Vector();

            st = list.get(i);
            v.addElement(st.getStudentId());
            v.addElement(st.getStudentName());
            v.addElement(st.getTotalMoney());
            v.addElement(st.getPaidMoney());
            v.addElement(st.getBanlance());

            vRow.addElement(v);
        }

        Vector vCol = new Vector();
        vCol.addElement("StudentId");
        vCol.addElement("StudentName");
        vCol.addElement("TotalMoney");
        vCol.addElement("PaidMoney");
        vCol.addElement("Balance");

        DefaultTableModel tblModel = new DefaultTableModel(vRow, vCol);
        tbStudentTakeExam.setModel(tblModel);
    }

    private void cmbClassNameItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbClassNameItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbClassNameItemStateChanged

    private void btnStaticticsTakeExamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStaticticsTakeExamActionPerformed
        // TODO add your handling code here:
        lbNumberStudent.setText("");
        txtMeassage.setText("");
        
        int result = tbStudentTakeExam.getRowCount();
        loadTableStExamStatictics();

        if (result == 0 && result == 0) {
            txtMeassage.setText("No results match.");
        } else {
            txtMeassage.setText(result + " results match.");
            lbNumberStudent.setText(" " + result + " Students");
        }

    }//GEN-LAST:event_btnStaticticsTakeExamActionPerformed

    private void btnStaticticNoExamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStaticticNoExamActionPerformed
        // TODO add your handling code here:
        lbNumberStudent.setText("");
        txtMeassage.setText("");
        int result = tbStudentTakeExam.getRowCount();
        loadTableStNoExamStatictics();

        if (result == 0 && result == 0) {
            txtMeassage.setText("No results match.");
        } else {
            txtMeassage.setText(result + " results match.");
            lbNumberStudent.setText(" " + result + " Students");
        }
    }//GEN-LAST:event_btnStaticticNoExamActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnReport;
    private javax.swing.JButton btnStaticticNoExam;
    private javax.swing.JButton btnStaticticsTakeExam;
    private javax.swing.JComboBox cmbClassName;
    private com.toedter.calendar.JDateChooser dcFrom;
    private com.toedter.calendar.JDateChooser dcTo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbNumberStudent;
    private javax.swing.JTable tbStudentTakeExam;
    private javax.swing.JLabel txtMeassage;
    // End of variables declaration//GEN-END:variables
}
